package Project4;

import java.util.*;

class FunctionCallStatement extends Statement{
	private String name;
	private ArrayList<ExpressionAssignment> functioncallVar = new ArrayList<ExpressionAssignment>();

	public FunctionCallStatement(String s){
		name = s;
	}

	public void addFunctioncallVar(ExpressionAssignment a){
		functioncallVar.add(a);
	}

	public String toString(){
		String r = "#--Function call--\n";
		
		r += "li $s1, 1\n";
		r += "add $sp, $sp, $s1\n";
		r += "sw $ra, ($sp)\n";
		for(int i = 0; i < 10; i++){
			r += "add $sp, $sp, $s1\n";
			r += "sw $t" + i + ", ($sp)\n";
		}

		r += "move $s2, $sp\n";
		for(int i = 0; i < functioncallVar.size(); i++){
			r += "add $s2, $s2, $s1\n";
			r += "li $t0, " + functioncallVar.get(i).getValue() + "\n";
			r += "sw $t0, ($s2) \n";
		}

		r += "jal " + name + "\n";

		for(int i = 9; i > -1; i--){
			r += "lw $t" + i + ", ($sp)\n";
			r += "sub $sp, $sp, $s1\n";
		}
		r += "lw $ra, ($sp)\n";
		r += "sub $sp, $sp, $t0\n";
		return r;
	}
}
